package 链表;

public class _203_移除链表元素 {
	public ListNode removeElements(ListNode head, int val) {
//		if (head == null) {
//			return head;
//		}
//		head.next = this.removeElements(head.next, val);
//		return head.val == val?head.next:head;

		
		if (head == null) {
			return head;
		}
		ListNode newHeadListNode = head;
		while (head.next != null) {
			if (head.next.val == val) {
				head.next = head.next.next;
			} else {
				head = head.next;
			}
			
		}
		if (newHeadListNode.val == val) {
			newHeadListNode = newHeadListNode.next;
		}
		return newHeadListNode;
	}
}
